SlideShare a Scribd company logo
Class No.22  Data Structures http://ecomputernotes.com
Deletion in AVL Tree There are 5 cases to consider. Let us go through the cases graphically and determine what action to take. We will not develop the C++ code for deleteNode in AVL tree. This will be left as an exercise. http://ecomputernotes.com
Deletion in AVL Tree Case 1a : the parent of the deleted node had a balance of 0 and the node was deleted in the parent’s  left  subtree. Action : change the balance of the parent node and stop. No further effect on balance of any higher node. Delete on this side http://ecomputernotes.com
Deletion in AVL Tree Here is why; the height of left tree does not change. 1 2 3 4 5 6 7 0 1 2 http://ecomputernotes.com
Deletion in AVL Tree Here is why; the height of left tree does not change. 1 2 3 4 5 6 7 2 3 4 5 6 7 0 1 2 remove(1) http://ecomputernotes.com
Deletion in AVL Tree Case 1b : the parent of the deleted node had a balance of 0 and the node was deleted in the parent’s  right  subtree. Action : (same as  1a )   change the balance of the parent node and stop. No further effect on balance of any higher node. Delete on this side http://ecomputernotes.com
Deletion in AVL Tree Case 2a : the parent of the deleted node had a balance of 1 and the node was deleted in the parent’s  left  subtree. Action : change the balance of the parent node. May have caused imbalance in higher nodes so continue up the tree. Delete on this side http://ecomputernotes.com
Deletion in AVL Tree Case 2b : the parent of the deleted node had a balance of -1 and the node was deleted in the parent’s  right  subtree. Action : same as 2a: change the balance of the parent node. May have caused imbalance in higher nodes so continue up the tree. Delete on this side http://ecomputernotes.com
Deletion in AVL Tree Case 3a : the parent had balance of -1 and the node was deleted in the parent’s  left  subtree, right subtree was balanced. http://ecomputernotes.com
Deletion in AVL Tree Case 3a : the parent had balance of -1 and the node was deleted in the parent’s  left  subtree, right subtree was balanced. Action : perform single rotation, adjust balance. No effect on balance of higher nodes so stop here. Single rotate http://ecomputernotes.com
Deletion in AVL Tree Case 4a : parent had balance of -1 and the node was deleted in the parent’s  left  subtree, right subtree was unbalanced. http://ecomputernotes.com
Deletion in AVL Tree Case 4a : parent had balance of -1 and the node was deleted in the parent’s  left  subtree, right subtree was unbalanced. Action : Double rotation at B. May have effected the balance of higher nodes, so continue up the tree. rotate double
Deletion in AVL Tree Case 5a : parent had balance of -1 and the node was deleted in the parent’s  left  subtree, right subtree was unbalanced. http://ecomputernotes.com
Deletion in AVL Tree Case 5a : parent had balance of -1 and the node was deleted in the parent’s  left  subtree, right subtree was unbalanced. Action : Single rotation at B. May have effected the balance of higher nodes, so continue up the tree. rotate single
Other Uses of Binary Trees Expression Trees http://ecomputernotes.com
Expression Trees Expression trees , and the more general parse trees and abstract syntax trees are significant components of compilers. Let us consider the expression tree. http://ecomputernotes.com
Expression Tree (a+b*c)+((d*e+f)*g) a c + b g * + + d * * e f http://ecomputernotes.com
Parse Tree in Compiler Expression grammar <assign>  <id> := <expr> <id>  A | B | C <expr>  <expr> + <term> | <term> <term>  <term> * <factor> | <factor>  <factor>  ( <expr> ) | <id> <assign> <id> <expr> <expr> <term> <term> <term> <factor> C B * + <id> <id> A := A <id> <factor> <factor> A := A + B * C
Parse Tree for an SQL query Consider querying a movie database Find the titles for movies with stars born in 1960 The database has tables StarsIn(title, year, starName) MovieStar(name, address, gender, birthdate) SELECT title FROM StarsIn, MovieStar WHERE starName = name AND birthdate LIKE ‘%1960’ ; http://ecomputernotes.com
SQL Parse Tree < Query > SELECT  <SelList>  FROM  <FromList>  WHERE  <Condition> <Attribute> <RelName> , <FromList>  AND title   StarsIn  <RelName>  <Condition>   <Condition> <Attribute>  =  <Attribute> <Attribute>  LIKE  <Pattern> starName name birthdate ‘%1960’ MovieStar http://ecomputernotes.com
Compiler Optimization Common subexpression: (f+d*e)+((d*e+f)*g) f e + d g * + + d * * e f http://ecomputernotes.com
Compiler Optimization (Common subexpression: (f+d*e)+((d*e+f)*g) f e + d g * + * Graph! http://ecomputernotes.com

More Related Content

PPTX
Pharm receptors ppt
PPT
computer notes - Data Structures - 18
PPT
computer notes - Data Structures - 17
PPT
computer notes - Data Structures - 31
PPT
computer notes - Data Structures - 34
PPT
computer notes - Data Structures - 26
PPT
computer notes - Data Structures - 29
PPT
computer notes - Data Structures - 12
Pharm receptors ppt
computer notes - Data Structures - 18
computer notes - Data Structures - 17
computer notes - Data Structures - 31
computer notes - Data Structures - 34
computer notes - Data Structures - 26
computer notes - Data Structures - 29
computer notes - Data Structures - 12

Viewers also liked (20)

PPT
computer notes - Data Structures - 4
PPT
computer notes - Data Structures - 20
PPT
computer notes - Data Structures - 14
PPT
computer notes - Data Structures - 15
PPT
computer notes - Data Structures - 13
PPT
computer notes - Data Structures - 3
PPT
computer notes - Data Structures - 10
PPT
computer notes - Data Structures - 8
PPT
computer notes - Data Structures - 11
PPT
computer notes - Data Structures - 19
PPT
computer notes - Data Structures - 33
PPT
computer notes - Data Structures - 39
PPT
computer notes - Data Structures - 7
PPT
computer notes - Data Structures - 2
PPT
computer notes - Data Structures - 32
PPT
computer notes - Data Structures - 1
PPT
computer notes - Data Structures - 27
PPT
computer notes - Data Structures - 28
PPT
computer notes - Data Structures - 9
PPT
computer notes - Data Structures - 35
computer notes - Data Structures - 4
computer notes - Data Structures - 20
computer notes - Data Structures - 14
computer notes - Data Structures - 15
computer notes - Data Structures - 13
computer notes - Data Structures - 3
computer notes - Data Structures - 10
computer notes - Data Structures - 8
computer notes - Data Structures - 11
computer notes - Data Structures - 19
computer notes - Data Structures - 33
computer notes - Data Structures - 39
computer notes - Data Structures - 7
computer notes - Data Structures - 2
computer notes - Data Structures - 32
computer notes - Data Structures - 1
computer notes - Data Structures - 27
computer notes - Data Structures - 28
computer notes - Data Structures - 9
computer notes - Data Structures - 35
Ad

Similar to computer notes - Data Structures - 22 (20)

PPT
Computernotes datastructures-22-111227202516-phpapp02
PPT
Computer notes - AVL Tree
PPT
avl trees avl trees avl trees avl trees avl trees avl trees avl trees
PPTX
AVL Tress
PPT
AVL Tree.ppt
PPTX
Avl trees
PPTX
Adelson velskii Landis rotations based on
PPT
Lecture no 16 data structure Balanced Trees.ppt
PPTX
Data structures trees and graphs - AVL tree.pptx
PDF
Im having trouble implementing a delete function for an AVL tree. .pdf
PPTX
GEC_Soumik[1].pptx.interview of a person from JU.
PDF
avl tree exampel and tree manipulation pdf
PPT
PPT
AVL TREE java dalam penerapannya dan aplikasinya
PDF
data structure AVL TREES chapter slides for learning about AVL trees
PDF
computer notes - Deleting a node
PPTX
AVL Tree concept in data structures.pptx
PPTX
PPTX
Presentation_30219_Content_Document_20250107125144AM.pptx
Computernotes datastructures-22-111227202516-phpapp02
Computer notes - AVL Tree
avl trees avl trees avl trees avl trees avl trees avl trees avl trees
AVL Tress
AVL Tree.ppt
Avl trees
Adelson velskii Landis rotations based on
Lecture no 16 data structure Balanced Trees.ppt
Data structures trees and graphs - AVL tree.pptx
Im having trouble implementing a delete function for an AVL tree. .pdf
GEC_Soumik[1].pptx.interview of a person from JU.
avl tree exampel and tree manipulation pdf
AVL TREE java dalam penerapannya dan aplikasinya
data structure AVL TREES chapter slides for learning about AVL trees
computer notes - Deleting a node
AVL Tree concept in data structures.pptx
Presentation_30219_Content_Document_20250107125144AM.pptx
Ad

More from ecomputernotes (17)

PPT
computer notes - Data Structures - 30
DOC
Computer notes - Including Constraints
DOC
Computer notes - Date time Functions
DOC
Computer notes - Subqueries
DOC
Computer notes - Other Database Objects
DOC
Computer notes - Advanced Subqueries
DOC
Computer notes - Aggregating Data Using Group Functions
PPT
computer notes - Data Structures - 16
PPT
computer notes - Data Structures - 36
DOC
Computer notes - Enhancements to the GROUP BY Clause
DOC
Computer notes - Manipulating Data
DOC
Computer notes - Writing Basic SQL SELECT Statements
PPT
computer notes - Data Structures - 5
DOC
Computer notes - Controlling User Access
DOC
Computer notes - Using SET Operator
PPT
computer notes - Data Structures - 38
PPT
computer notes - Data Structures - 25
computer notes - Data Structures - 30
Computer notes - Including Constraints
Computer notes - Date time Functions
Computer notes - Subqueries
Computer notes - Other Database Objects
Computer notes - Advanced Subqueries
Computer notes - Aggregating Data Using Group Functions
computer notes - Data Structures - 16
computer notes - Data Structures - 36
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Manipulating Data
Computer notes - Writing Basic SQL SELECT Statements
computer notes - Data Structures - 5
Computer notes - Controlling User Access
Computer notes - Using SET Operator
computer notes - Data Structures - 38
computer notes - Data Structures - 25

Recently uploaded (20)

PDF
Five Habits of High-Impact Board Members
PDF
Unlock new opportunities with location data.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPTX
The various Industrial Revolutions .pptx
PPT
Geologic Time for studying geology for geologist
PDF
Getting Started with Data Integration: FME Form 101
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
STKI Israel Market Study 2025 version august
PPTX
observCloud-Native Containerability and monitoring.pptx
Five Habits of High-Impact Board Members
Unlock new opportunities with location data.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
A review of recent deep learning applications in wood surface defect identifi...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Tartificialntelligence_presentation.pptx
Assigned Numbers - 2025 - Bluetooth® Document
A contest of sentiment analysis: k-nearest neighbor versus neural network
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Enhancing emotion recognition model for a student engagement use case through...
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
The various Industrial Revolutions .pptx
Geologic Time for studying geology for geologist
Getting Started with Data Integration: FME Form 101
Developing a website for English-speaking practice to English as a foreign la...
Module 1.ppt Iot fundamentals and Architecture
Hindi spoken digit analysis for native and non-native speakers
STKI Israel Market Study 2025 version august
observCloud-Native Containerability and monitoring.pptx

computer notes - Data Structures - 22

  • 1. Class No.22 Data Structures http://ecomputernotes.com
  • 2. Deletion in AVL Tree There are 5 cases to consider. Let us go through the cases graphically and determine what action to take. We will not develop the C++ code for deleteNode in AVL tree. This will be left as an exercise. http://ecomputernotes.com
  • 3. Deletion in AVL Tree Case 1a : the parent of the deleted node had a balance of 0 and the node was deleted in the parent’s left subtree. Action : change the balance of the parent node and stop. No further effect on balance of any higher node. Delete on this side http://ecomputernotes.com
  • 4. Deletion in AVL Tree Here is why; the height of left tree does not change. 1 2 3 4 5 6 7 0 1 2 http://ecomputernotes.com
  • 5. Deletion in AVL Tree Here is why; the height of left tree does not change. 1 2 3 4 5 6 7 2 3 4 5 6 7 0 1 2 remove(1) http://ecomputernotes.com
  • 6. Deletion in AVL Tree Case 1b : the parent of the deleted node had a balance of 0 and the node was deleted in the parent’s right subtree. Action : (same as 1a ) change the balance of the parent node and stop. No further effect on balance of any higher node. Delete on this side http://ecomputernotes.com
  • 7. Deletion in AVL Tree Case 2a : the parent of the deleted node had a balance of 1 and the node was deleted in the parent’s left subtree. Action : change the balance of the parent node. May have caused imbalance in higher nodes so continue up the tree. Delete on this side http://ecomputernotes.com
  • 8. Deletion in AVL Tree Case 2b : the parent of the deleted node had a balance of -1 and the node was deleted in the parent’s right subtree. Action : same as 2a: change the balance of the parent node. May have caused imbalance in higher nodes so continue up the tree. Delete on this side http://ecomputernotes.com
  • 9. Deletion in AVL Tree Case 3a : the parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was balanced. http://ecomputernotes.com
  • 10. Deletion in AVL Tree Case 3a : the parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was balanced. Action : perform single rotation, adjust balance. No effect on balance of higher nodes so stop here. Single rotate http://ecomputernotes.com
  • 11. Deletion in AVL Tree Case 4a : parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. http://ecomputernotes.com
  • 12. Deletion in AVL Tree Case 4a : parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. Action : Double rotation at B. May have effected the balance of higher nodes, so continue up the tree. rotate double
  • 13. Deletion in AVL Tree Case 5a : parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. http://ecomputernotes.com
  • 14. Deletion in AVL Tree Case 5a : parent had balance of -1 and the node was deleted in the parent’s left subtree, right subtree was unbalanced. Action : Single rotation at B. May have effected the balance of higher nodes, so continue up the tree. rotate single
  • 15. Other Uses of Binary Trees Expression Trees http://ecomputernotes.com
  • 16. Expression Trees Expression trees , and the more general parse trees and abstract syntax trees are significant components of compilers. Let us consider the expression tree. http://ecomputernotes.com
  • 17. Expression Tree (a+b*c)+((d*e+f)*g) a c + b g * + + d * * e f http://ecomputernotes.com
  • 18. Parse Tree in Compiler Expression grammar <assign>  <id> := <expr> <id>  A | B | C <expr>  <expr> + <term> | <term> <term>  <term> * <factor> | <factor> <factor>  ( <expr> ) | <id> <assign> <id> <expr> <expr> <term> <term> <term> <factor> C B * + <id> <id> A := A <id> <factor> <factor> A := A + B * C
  • 19. Parse Tree for an SQL query Consider querying a movie database Find the titles for movies with stars born in 1960 The database has tables StarsIn(title, year, starName) MovieStar(name, address, gender, birthdate) SELECT title FROM StarsIn, MovieStar WHERE starName = name AND birthdate LIKE ‘%1960’ ; http://ecomputernotes.com
  • 20. SQL Parse Tree < Query > SELECT <SelList> FROM <FromList> WHERE <Condition> <Attribute> <RelName> , <FromList> AND title StarsIn <RelName> <Condition> <Condition> <Attribute> = <Attribute> <Attribute> LIKE <Pattern> starName name birthdate ‘%1960’ MovieStar http://ecomputernotes.com
  • 21. Compiler Optimization Common subexpression: (f+d*e)+((d*e+f)*g) f e + d g * + + d * * e f http://ecomputernotes.com
  • 22. Compiler Optimization (Common subexpression: (f+d*e)+((d*e+f)*g) f e + d g * + * Graph! http://ecomputernotes.com

Editor's Notes

  • #4: Start of lecture 24
  • #8: End of lecture 23.
  • #23: End of lecture 24.